// Copyright 2011 Jay Young. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
 * @fileoverview
 *
 * A Service Provider for the Relieved Blog.
 */

goog.provide('rb.ServiceProvider');

goog.require('relief.handlers.CommonServiceProvider');



/**
 * A Service Provider implementation that extends CommonServiceProvider to also
 * include an event bus.
 *
 * @param {goog.events.EventTarget} eventBus The app's event bus.
 * @param {relief.nav.URLMap} urlMap The mapping from URL hash codes to Handler
 *    constructors.
 * @param {relief.cache.Cache} cache The app's cache.
 * @param {relief.rpc.RPCService} rpc The app's RPC Service.
 * @param {relief.auth.AuthManager} auth The app's auth manager instance.
 * @param {!HTMLIFrameElement} iframe The iframe to be used by the goog.History
 *    object.
 * @param {!HTMLInputElement} input The hidden input field to be used by the
 *    goog.History object.
 * @param {!Element} content The root element into which handlers should inject
 *    content.
 *
 * @constructor
 * @extends {relief.handlers.CommonServiceProvider}
 */
rb.ServiceProvider = function(eventBus, urlMap, cache, rpc, auth, 
                              iframe, input, content) {
  goog.base(this, urlMap, cache, rpc, auth, iframe, input, content);

  /**
   * @type {goog.events.EventTarget}
   * @private
   */
  this.eventBus_ = eventBus;
};
goog.inherits(rb.ServiceProvider, relief.handlers.CommonServiceProvider);


/**
 * @return {goog.events.EventTarget} The app's event bus.
 */
rb.ServiceProvider.prototype.getEventBus = function() {
  return this.eventBus_;
};


/**
 * @inheritDoc
 */
rb.ServiceProvider.prototype.disposeInternal = function() {
  goog.base(this, 'disposeInternal');

  this.eventBus_.dispose();
  this.eventBus_ = null;
};
